<?php

class AdministratorsController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
         $this->view->headMeta()->appendHttpEquiv('Content-Type','text-html;charset=UTF-8');
    }

    public function indexAction()
    {
        // action body
        // kiem tra cac quyen
        $user = new Zend_Session_NameSpace("user");
            if(isset($user->username)&&$user->level==1&&$user->trangthai==1){
                $userModel=new Model_User;
                $username=$userModel->getAll();
                $unlock=$userModel->getUnlock();
                $lock=$userModel->getLock();
                $tinModel=new Model_Tin;
                $tin=$tinModel->getAll();
                $this->view->unlock=$unlock;
                $this->view->lock=$lock;
                $this->view->user=$username;
                $this->view->tin=$tin;
            }  else {
                $this->_redirect("/index");
            }
    }

    public function lockuserAction()
    {
        // action body
        $userModel=new Model_User;
        $getiduser=$this->_request->getParam("iduser");
        $setdata=array('trangthai'=>'2','level'=>'0');
        $kq=$userModel->setLock($setdata, $getiduser);
        if ($kq==true) {
            $this->_redirect("/administrators/index");
        }  else {
            echo "lỗi";
        }
    }

    public function unlockuserAction()
    {
        // action body
        $userModel=new Model_User;
        $getiduser=$this->_request->getParam("iduser");
        $setdata=array('trangthai'=>'1','level'=>'2');
        $kq=$userModel->setUnlock($setdata, $getiduser);
        if ($kq==true) {
            $this->_redirect("/administrators/index");
        }  else {
            echo "lỗi";
        }
    }

    public function manageruserAction()
    {
        // action body
         $user = new Zend_Session_NameSpace("user");
            if(isset($user->username)&&$user->level==1&&$user->trangthai==1){
                $userModel=new Model_User;
                $username=$userModel->getAll();
                $this->view->user=$username;
            }  else {
                $this->_redirect("/index");
            }
    }


}







